﻿using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace WPFNote.Utilities.ReturnJson
{

    /// <summary>
    /// 数据返回模型
    /// </summary>
    public class ServerJsonResult
    {
        /// <summary>
        /// 代码，200成功，400错误请求，401身份验证错误，403禁止访问，404未找到
        /// </summary>
        [JsonProperty(PropertyName = "code")]
        public int Code { get; set; } = 200;
        /// <summary>
        /// 携带的JSON数据
        /// </summary>
        [JsonProperty(PropertyName = "data")]
        public string Data { get; set; }

        private string _message;
        /// <summary>
        /// 消息
        /// </summary>
        [JsonProperty(PropertyName = "message")]
        public string Message
        {
            get
            {
                if (string.IsNullOrEmpty(_message) && Code == 200)
                {
                    _message = "操作成功";
                }
                return _message;
            }
            set => _message = value;
        }
        /// <summary>
        /// 回调地址
        /// </summary>
        [JsonIgnore]
        [JsonProperty(PropertyName = "redirect")]
        public string Redirect { get; set; }

    }

    public class DataSource<T>
    {
        /// <summary>
        /// 数据列表
        /// </summary>
        public List<T> Data { get; set; }

        /// <summary>
        /// 数据行数
        /// </summary>
        public int Rs { get; set; }
    }
}
